/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Interact;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import ConnectDB.ConnectDB;
import Validate_Connect.DataInteraction;
/**
 *
 * @author Shinichi
 */
public class Sub_Trains {
    public static boolean insertSub_train(Entity.Sub_Train sub){
        try {
            String sql = "insert into tblSub_Train values (?,?)";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, sub.get_TrainID());
            ps.setString(2, sub.get_SubID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Sub_Trains.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static boolean updateSub_Train(Entity.Sub_Train subT){
        try {
            String sql = "update tblSub_Train set SubID=? where TrainID=?";
            PreparedStatement ps = DataInteraction.getConnect().prepareStatement(sql);
            ps.setString(1, subT.get_SubID());
            ps.setString(2, subT.get_TrainID());
            return ps.executeUpdate() == 1;
        } catch (SQLException ex) {
            Logger.getLogger(Sub_Trains.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static void deleteSub_Train(String strTrainID)
    {
        try {
            String sql = "delete from tblSub_Train where TrainID= '" + strTrainID + "'";
            Statement st;
            st = DataInteraction.getConnect().createStatement();
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Sub_Trains.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
